//package com.zmn.plat.dubbo.impl.product.productgroup;
//
//import com.zmn.common.dto.VtDTO;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.collection.CollectionUtil;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.common.utils.reflect.BeanMapper;
//import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
//import com.zmn.plat.common.dictionary.PlatErrorCodeDict;
//import com.zmn.plat.common.dto.product.productgroup.ProductGroupDRO;
//import com.zmn.plat.common.dto.product.productgroup.ProductGroupNameAndBizTypeDRO;
//import com.zmn.plat.common.exception.PlatException;
//import com.zmn.plat.dubbo.interfaces.product.productgroup.ProductGroupListRemoteService;
//import com.zmn.plat.dubbo.utils.DubboConsts;
//import com.zmn.plat.model.entity.product.productgroup.ProductGroup;
//import com.zmn.plat.model.entity.product.productgroup.ProductGroupQuery;
//import com.zmn.plat.model.vo.product.productgroup.ProductGroupVO;
//import com.zmn.plat.services.interfaces.product.productgroup.ProductGroupService;
//import com.zmn.plat.utils.bean.BeanCopyUtils;
//import io.swagger.annotations.Api;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.config.annotation.Service;
//import org.springframework.util.CollectionUtils;
//
//import javax.annotation.Resource;
//import javax.validation.constraints.NotNull;
//import javax.validation.constraints.Positive;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
///**
// * 产品组dubbo接口类
// *
// * @auther: tanghongjun
// * @since: 2020年8月25日10:12:08
// */
//@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
//@Api(value = "产品组远程服务", tags = {"产品组"})
//@Slf4j
//public class ProductGroupListRemoteServiceImpl implements ProductGroupListRemoteService {
//
//    @Resource
//    ProductGroupService productGroupService;
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<VtDTO> getNameVtById(@NotNull(message = "groupId不能为空") @Positive(message = "groupId必须为大于0的正整数") Integer groupId) {
//        log.info("getNameVtById：groupId={}", groupId);
//
//        ProductGroup productGroup = productGroupService.findById(groupId);
//
//        if (Objects.isNull(productGroup)) {
//            log.error("productGroup not Exist.groupId:{},errorCode:{}", groupId, PlatErrorCodeDict.ERROR_CODE_PRODUCT_GROUP_NO_DATA);
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PRODUCT_GROUP_NO_DATA);
//        }
//
//        return ResponseDTO.success(new VtDTO(groupId, productGroup.getName()));
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ProductGroupNameAndBizTypeDRO>> listNameAndBizTypeVtByIdList(List<Integer> groupIdList) {
//
//        log.info("listNameAndBizTypeVtByIdList, bizType:{}，groupIdList:{}", groupIdList);
//
//        try {
//            List<ProductGroup> productGroupList = productGroupService.listByIdList(groupIdList);
//            List<ProductGroupNameAndBizTypeDRO> dtos = productGroupList.stream()
//                    .map(productGroup -> new ProductGroupNameAndBizTypeDRO(productGroup.getGroupId(),productGroup.getGroupCode(), productGroup.getName(), productGroup.getBizType())).distinct().collect(Collectors.toList());
//            return ResponseDTO.success(dtos);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ProductGroupDRO>> listTreeByStatus(Integer status) {
//        log.info("listTreeByStatus：status:{}", status);
//
//        List<ProductGroupDRO> list = new ArrayList<>();
//        List<ProductGroupVO> groupVOList = productGroupService.listTreeByStatus(status);
//        if (!CollectionUtils.isEmpty(groupVOList)) {
//            list = BeanCopyUtils.copyProperties(groupVOList, ProductGroupVO.class, ProductGroupDRO.class, ProductGroupDRO::new);
//        }
//        return ResponseDTO.success(list);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByNameListAndBizType(Integer bizType, List<String> nameList) {
//        log.info("listVtByNameListAndBizType：bizType:{}，nameList:{}", bizType, nameList);
//
//        try {
//            List<ProductGroup> productGroupList = productGroupService.listByNameListAndBizType(bizType, nameList);
//            List<VtDTO> dtos =
//                    productGroupList.stream().map(productGroup -> new VtDTO(productGroup.getGroupId(), productGroup.getName(), productGroup.getStatus())).distinct().collect(Collectors.toList());
//            return ResponseDTO.success(dtos);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByBizType(Integer bizType, Integer status) {
//        log.info("listVtByBizType：bizType={},status={}", bizType, status);
//
//        ProductGroupQuery query = new ProductGroupQuery();
//        query.setBizType(bizType);
//        query.setStatus(status);
//        List<ProductGroup> productGroupList = productGroupService.listByQuery(query);
//
//        if (CollectionUtil.isNullOrEmpty(productGroupList)) {
//            log.error("productGroupList is empty.errorCode:{}", PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//        }
//
//        List<VtDTO> dtos = productGroupList.stream().map(productGroup -> new VtDTO(productGroup.getGroupId(), productGroup.getName())).distinct().collect(Collectors.toList());
//
//        return ResponseDTO.success(dtos);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByBizTypeList(List<Integer> bizTypeList, Integer status) {
//        log.info("listVtByBizType：bizTypeList={},status={}", bizTypeList, status);
//
//        ProductGroupQuery query = new ProductGroupQuery();
//        query.setBizTypeList(bizTypeList);
//        query.setStatus(status);
//        List<ProductGroup> productGroupList = productGroupService.listByQuery(query);
//
//        if (CollectionUtil.isNullOrEmpty(productGroupList)) {
//            log.error("productGroupList is empty.errorCode:{}", PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//        }
//
//        List<VtDTO> dtos = productGroupList.stream().map(productGroup -> new VtDTO(productGroup.getGroupId(), productGroup.getName())).distinct().collect(Collectors.toList());
//
//        return ResponseDTO.success(dtos);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ProductGroupDRO>> listByBizTypeList(List<Integer> bizTypeList, Integer status) {
//
//        ProductGroupQuery query = new ProductGroupQuery();
//        query.setBizTypeList(bizTypeList);
//        query.setStatus(status);
//        List<ProductGroup> productGroupList = productGroupService.listByQuery(query);
//        if (CollectionUtil.isNullOrEmpty(productGroupList)) {
//            log.error("productGroupList is empty.errorCode:{}", PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//        }
//        List<ProductGroupDRO> result = BeanMapper.mapList(productGroupList, ProductGroupDRO.class);
//        return ResponseDTO.success(result);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByBusinesslineIdAndStatus(Integer businessLineId, Integer status) {
//        log.info("listVtByBusinesslineIdAndStatus：businessLineId={},status={}", businessLineId, status);
//
//        ProductGroupQuery query = new ProductGroupQuery();
//        query.setBizLine(businessLineId);
//        query.setStatus(status);
//        List<ProductGroup> productGroupList = productGroupService.listByQuery(query);
//
//        if (CollectionUtil.isNullOrEmpty(productGroupList)) {
//            log.error("productGroupList is empty.errorCode:{}", PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PRODUCT_BIZTYPE_NO_GROUP_DATA);
//        }
//
//        List<VtDTO> dtos = productGroupList.stream().map(productGroup -> new VtDTO(productGroup.getGroupId(), productGroup.getName())).distinct().collect(Collectors.toList());
//
//        return ResponseDTO.success(dtos);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ProductGroupDRO>> listByGroupIdsAndStatus(List<Integer> groupIdList, Integer status) {
//        log.info("listByGroupIdsAndStatus, status:{}，groupIdList:{}", status, groupIdList);
//        List<ProductGroupDRO> groupDROList = new ArrayList<>();
//        try {
//            List<ProductGroup> productGroupList = productGroupService.listByIdList(groupIdList);
//            if (NumberUtil.isPositiveInteger(status)) {
//                productGroupList = productGroupList.stream().filter(e -> Objects.equals(e.getStatus(), status)).collect(Collectors.toList());
//            }
//            if (!CollectionUtils.isEmpty(productGroupList)) {
//                groupDROList.addAll(BeanCopyUtils.copyProperties(productGroupList, ProductGroup.class, ProductGroupDRO.class, ProductGroupDRO::new));
//            }
//            return ResponseDTO.success(groupDROList);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ProductGroupDRO>> listAllProductGroup() {
//        ProductGroupQuery query = new ProductGroupQuery();
//        query.setStatus(2);
//        List<ProductGroup> productGroupList = productGroupService.listByQuery(query);
//        if (CollectionUtil.isNullOrEmpty(productGroupList)) {
//            return ResponseDTO.success(new ArrayList<>());
//        }
//        List<ProductGroupDRO> result = BeanMapper.mapList(productGroupList, ProductGroupDRO.class);
//        return ResponseDTO.success(result);
//    }
//}
